﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="detailandmed_v5_registrikaart", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(DetailandmedV5Registrikaart))]
    public class DetailandmedV5RegistrikaartSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IDetailandmedV5Registrikaart clazz;
        
        public DetailandmedV5RegistrikaartSerializer(IDetailandmedV5Registrikaart clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.KirjeId!=null) {
                Writer.WriteStartElement("kirje_id");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.KirjeId))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.KaardiPiirkond!=null) {
                Writer.WriteStartElement("kaardi_piirkond");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.KaardiPiirkond))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.KaardiNr!=null) {
                Writer.WriteStartElement("kaardi_nr");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.KaardiNr))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.KaardiTyyp!=null) {
                Writer.WriteStartElement("kaardi_tyyp");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.KaardiTyyp))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Kanded!=null) {
                Writer.WriteStartElement("kanded");
                global::Xtee.Core.SerializationMetadata metaKanded = this.GetMetaData(clazz.Kanded);
                Writer.WriteTypeAttribute(metaKanded.TypeQualifiedName.Namespace, metaKanded.TypeQualifiedName.Name);
                metaKanded.NewSerializer(clazz.Kanded).WriteXml(Writer);
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="kirje_id") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_v5_registrikaart>kirje_id");
                }
                clazz.KirjeId = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("kirje_id")).Value;
            }
            if (Reader.LocalName=="kaardi_piirkond") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_v5_registrikaart>kaardi_piirkond");
                }
                clazz.KaardiPiirkond = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("kaardi_piirkond")).Value;
            }
            if (Reader.LocalName=="kaardi_nr") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_v5_registrikaart>kaardi_nr");
                }
                clazz.KaardiNr = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("kaardi_nr")).Value;
            }
            if (Reader.LocalName=="kaardi_tyyp") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_v5_registrikaart>kaardi_tyyp");
                }
                clazz.KaardiTyyp = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kaardi_tyyp")).Value;
            }
            if (Reader.LocalName=="kanded") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_v5_registrikaart>kanded");
                }
                global::Xtee.Core.SerializationMetadata metaKanded = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedV5Kanded>(Reader, "detailandmed_v5_kanded", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                clazz.Kanded = metaKanded.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedV5Kanded>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("kanded");
                    metaKanded.NewSerializer(clazz.Kanded).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
        }
    }
}
